package com.video.commons.runtimelog;

import com.qf.entity.RunLogEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * 日志记录工具类，通过该类进行日志的记录
 * @Author ken
 * @Time 2018/11/8 16:30
 * @Version 1.0
 */
@Slf4j
public class RunLogUtil {


    /**
     * 记录日志对象
     * @param runLogEntity
     */
    public static void runLog(RabbitTemplate rabbitTemplate, RunLogEntity runLogEntity){

        //将日志发送给ElasticSearch
//        rabbitTemplate.convertAndSend("runlog_exchange", "", runLogEntity);
        //记录当前日志
        log.debug(setContent(runLogEntity.toString()));
    }

    public static void info(String info){
        log.info(setContent(info));
    }

    public static void debug(String debug){
        log.debug(setContent(debug));
    }

    public static void warn(String debug){
        log.warn(setContent(debug));
    }

    public static void error(String error, Throwable e){
        log.error(setContent(error), e);
    }

    /**
     * 设置日志内容格式
     * @return
     */
    private static String setContent(String content){
        //获取当前请求编号
        String id = RequestIdThreadLocal.getId();
        content = String.format("[RequestId: %s] \n %s", id, content);
        return content;
    }
}
